{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Twisted WS2 Bilayers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## import & prepare" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Collecting git+https://github.com/nmdl-mizo/interface_master.git@develop\n", " Cloning https://github.com/nmdl-mizo/interface_master.git (to revision develop) to /tmp/pip-req-build-imt8qeri\n", " Running command git clone --filter=blob:none --quiet https://github.com/nmdl-mizo/interface_master.git /tmp/pip-req-build-imt8qeri\n", " Resolved https://github.com/nmdl-mizo/interface_master.git to commit f5666609400c80ae72c32471aeeaf5b80e4684e1\n", " Preparing metadata (setup.py) ... \u001b[?25ldone\n", "\u001b[?25hRequirement already satisfied: pymatgen in /home/vscode/.local/lib/python3.10/site-packages (from interfacemaster==1.1.1) (2023.1.30)\n", "Requirement already satisfied: matplotlib in /home/vscode/.local/lib/python3.10/site-packages (from interfacemaster==1.1.1) (3.7.0)\n", "Requirement already satisfied: gb_code in /home/vscode/.local/lib/python3.10/site-packages (from interfacemaster==1.1.1) (1.0.0)\n", "Requirement already satisfied: numpy>=1.14.0 in /home/vscode/.local/lib/python3.10/site-packages (from gb_code->interfacemaster==1.1.1) (1.24.2)\n", "Requirement already satisfied: contourpy>=1.0.1 in /home/vscode/.local/lib/python3.10/site-packages (from matplotlib->interfacemaster==1.1.1) (1.0.7)\n", "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/site-packages (from matplotlib->interfacemaster==1.1.1) (23.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /home/vscode/.local/lib/python3.10/site-packages (from matplotlib->interfacemaster==1.1.1) (1.4.4)\n", "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/site-packages (from matplotlib->interfacemaster==1.1.1) (2.8.2)\n", "Requirement already satisfied: pyparsing>=2.3.1 in /home/vscode/.local/lib/python3.10/site-packages (from matplotlib->interfacemaster==1.1.1) (3.0.9)\n", "Requirement already satisfied: pillow>=6.2.0 in /home/vscode/.local/lib/python3.10/site-packages (from matplotlib->interfacemaster==1.1.1) (9.4.0)\n", "Requirement already satisfied: cycler>=0.10 in /home/vscode/.local/lib/python3.10/site-packages (from matplotlib->interfacemaster==1.1.1) (0.11.0)\n", "Requirement already satisfied: fonttools>=4.22.0 in /home/vscode/.local/lib/python3.10/site-packages (from matplotlib->interfacemaster==1.1.1) (4.38.0)\n", "Requirement already satisfied: ruamel.yaml>=0.17.0 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (0.17.21)\n", "Requirement already satisfied: tabulate in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (0.9.0)\n", "Requirement already satisfied: monty>=3.0.2 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (2022.9.9)\n", "Requirement already satisfied: sympy in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (1.11.1)\n", "Requirement already satisfied: uncertainties>=3.1.4 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (3.1.7)\n", "Requirement already satisfied: pandas in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (1.5.3)\n", "Requirement already satisfied: mp-api>=0.27.3 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (0.30.10)\n", "Requirement already satisfied: palettable>=3.1.1 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (3.3.0)\n", "Requirement already satisfied: plotly>=4.5.0 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (5.13.0)\n", "Requirement already satisfied: pybtex in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (0.24.0)\n", "Requirement already satisfied: networkx>=2.2 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (3.0)\n", "Requirement already satisfied: tqdm in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (4.64.1)\n", "Requirement already satisfied: scipy>=1.5.0 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (1.10.1)\n", "Requirement already satisfied: spglib>=2.0.2 in /home/vscode/.local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (2.0.2)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.10/site-packages (from pymatgen->interfacemaster==1.1.1) (2.28.2)\n", "Requirement already satisfied: typing-extensions>=3.7.4.1 in /home/vscode/.local/lib/python3.10/site-packages (from mp-api>=0.27.3->pymatgen->interfacemaster==1.1.1) (4.5.0)\n", "Requirement already satisfied: setuptools in /usr/local/lib/python3.10/site-packages (from mp-api>=0.27.3->pymatgen->interfacemaster==1.1.1) (65.5.1)\n", "Requirement already satisfied: msgpack in /home/vscode/.local/lib/python3.10/site-packages (from mp-api>=0.27.3->pymatgen->interfacemaster==1.1.1) (1.0.4)\n", "Requirement already satisfied: emmet-core>=0.39.8 in /home/vscode/.local/lib/python3.10/site-packages (from mp-api>=0.27.3->pymatgen->interfacemaster==1.1.1) (0.44.0)\n", "Requirement already satisfied: tenacity>=6.2.0 in /home/vscode/.local/lib/python3.10/site-packages (from plotly>=4.5.0->pymatgen->interfacemaster==1.1.1) (8.2.1)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib->interfacemaster==1.1.1) (1.16.0)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/site-packages (from requests->pymatgen->interfacemaster==1.1.1) (2022.12.7)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/site-packages (from requests->pymatgen->interfacemaster==1.1.1) (3.0.1)\n", "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/site-packages (from requests->pymatgen->interfacemaster==1.1.1) (1.26.14)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/site-packages (from requests->pymatgen->interfacemaster==1.1.1) (3.4)\n", "Requirement already satisfied: ruamel.yaml.clib>=0.2.6 in /home/vscode/.local/lib/python3.10/site-packages (from ruamel.yaml>=0.17.0->pymatgen->interfacemaster==1.1.1) (0.2.7)\n", "Requirement already satisfied: future in /home/vscode/.local/lib/python3.10/site-packages (from uncertainties>=3.1.4->pymatgen->interfacemaster==1.1.1) (0.18.3)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/site-packages (from pandas->pymatgen->interfacemaster==1.1.1) (2022.7.1)\n", "Requirement already satisfied: latexcodec>=1.0.4 in /home/vscode/.local/lib/python3.10/site-packages (from pybtex->pymatgen->interfacemaster==1.1.1) (2.0.1)\n", "Requirement already satisfied: PyYAML>=3.01 in /usr/local/lib/python3.10/site-packages (from pybtex->pymatgen->interfacemaster==1.1.1) (6.0)\n", "Requirement already satisfied: mpmath>=0.19 in /home/vscode/.local/lib/python3.10/site-packages (from sympy->pymatgen->interfacemaster==1.1.1) (1.2.1)\n", "Requirement already satisfied: pydantic>=1.10.2 in /home/vscode/.local/lib/python3.10/site-packages (from emmet-core>=0.39.8->mp-api>=0.27.3->pymatgen->interfacemaster==1.1.1) (1.10.5)\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.0.1\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", "100 951 100 951 0 0 2962 0 --:--:-- --:--:-- --:--:-- 2962\n", " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", "100 799 100 799 0 0 1026 0 --:--:-- --:--:-- --:--:-- 1025\n" ] } ], "source": [ "!pip install git+https://github.com/nmdl-mizo/interface_master.git@develop\n", "!mkdir -p cif_files\n", "!curl https://raw.githubusercontent.com/nmdl-mizo/interface_master/develop/test_files/cif_files/WS2_mp-224_conventional_standard.cif -o 'cif_files/WS2_mp-224_conventional_standard.cif'\n", "!curl https://raw.githubusercontent.com/nmdl-mizo/interface_master/develop/test_files/cif_files/WS2_single_layer.cif -o 'cif_files/WS2_single_layer.cif'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from interfacemaster.cellcalc import get_primitive_hkl, get_pri_vec_inplane, get_normal_index, get_normal_from_MI, rot\n", "from interfacemaster.interface_generator import core, convert_vector_index\n", "from interfacemaster.symmetric_tilt import get_csl_twisted_graphenes\n", "from numpy import array, dot, round, cross, eye, pi, ceil, column_stack, arange\n", "from numpy.linalg import inv, det, norm\n", "from gb_code.csl_generator import print_list\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from pymatgen.core.structure import Structure" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Define a get_csl_twisted_graphenes class" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/vscode/.local/lib/python3.10/site-packages/pymatgen/io/cif.py:1169: UserWarning: Issues encountered while parsing CIF: Some fractional coordinates rounded to ideal values to avoid issues with finite precision.\n", " warnings.warn(\"Issues encountered while parsing CIF: \" + \"\\n\".join(self.warnings))\n" ] } ], "source": [ "#sigmas, rotation angles, CNID areas, num of atoms\n", "sigmas, thetas, A_cnid, anum = get_csl_twisted_graphenes(lim = 10, filename = \\\n", " 'cif_files/WS2_mp-224_conventional_standard.cif',\\\n", " maxsigma = 2500, verbose=False)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sigmathetasCNID areaatom number
1721.7867891.25954228
21332.2042280.67821552
31913.1735510.46404276
43117.8965510.284413124
5379.4300080.238292148
64315.1781790.205042172
74916.4264210.179935196
8617.3409930.144538244
96735.5673020.131594268
107311.6350510.120778292
117926.0078240.111605316
12916.0089830.096888364
139729.4093110.090895388
1410319.6528600.085600412
1510910.9927330.080888436
161275.0858480.069424508
171338.6132380.066292532
1813934.5389440.063430556
1915118.7339980.058389604
2016336.5169380.054091652
211694.4084550.052170676
2218130.1582760.048712724
231938.2556210.045683772
242173.8902380.040630868
2522319.2748070.039537892
2622926.7456520.038501916
2724714.6222210.035696988
2825928.7832030.0340421036
292713.4810060.0325341084
3027717.2782440.0318301108
3128324.0166020.0311551132
323016.6086100.0292921204
333313.1496570.0266371324
3433715.6541440.0261631348
3536711.9851000.0240241468
3637923.7135820.0232631516
3740314.3076760.0218781612
3840919.9320130.0215571636
3945727.0524180.0192931828
4048118.3657650.0183301924
4152320.1465840.0168582092
4255917.0260490.0157722236
4361323.3018030.0143832452
\n", "
" ], "text/plain": [ " sigma thetas CNID area atom number\n", "1 7 21.786789 1.259542 28\n", "2 13 32.204228 0.678215 52\n", "3 19 13.173551 0.464042 76\n", "4 31 17.896551 0.284413 124\n", "5 37 9.430008 0.238292 148\n", "6 43 15.178179 0.205042 172\n", "7 49 16.426421 0.179935 196\n", "8 61 7.340993 0.144538 244\n", "9 67 35.567302 0.131594 268\n", "10 73 11.635051 0.120778 292\n", "11 79 26.007824 0.111605 316\n", "12 91 6.008983 0.096888 364\n", "13 97 29.409311 0.090895 388\n", "14 103 19.652860 0.085600 412\n", "15 109 10.992733 0.080888 436\n", "16 127 5.085848 0.069424 508\n", "17 133 8.613238 0.066292 532\n", "18 139 34.538944 0.063430 556\n", "19 151 18.733998 0.058389 604\n", "20 163 36.516938 0.054091 652\n", "21 169 4.408455 0.052170 676\n", "22 181 30.158276 0.048712 724\n", "23 193 8.255621 0.045683 772\n", "24 217 3.890238 0.040630 868\n", "25 223 19.274807 0.039537 892\n", "26 229 26.745652 0.038501 916\n", "27 247 14.622221 0.035696 988\n", "28 259 28.783203 0.034042 1036\n", "29 271 3.481006 0.032534 1084\n", "30 277 17.278244 0.031830 1108\n", "31 283 24.016602 0.031155 1132\n", "32 301 6.608610 0.029292 1204\n", "33 331 3.149657 0.026637 1324\n", "34 337 15.654144 0.026163 1348\n", "35 367 11.985100 0.024024 1468\n", "36 379 23.713582 0.023263 1516\n", "37 403 14.307676 0.021878 1612\n", "38 409 19.932013 0.021557 1636\n", "39 457 27.052418 0.019293 1828\n", "40 481 18.365765 0.018330 1924\n", "41 523 20.146584 0.016858 2092\n", "42 559 17.026049 0.015772 2236\n", "43 613 23.301803 0.014383 2452" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.DataFrame(column_stack((sigmas, thetas/pi*180, A_cnid, anum)), index = arange(len(sigmas))+1, \\\n", " columns = ['sigma','thetas','CNID area','atom number'])\n", "df['sigma'] = df['sigma'].astype('int')\n", "df['atom number'] = df['atom number'].astype('int')\n", "df" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Warning!, this programme will rewrite the POSCAR file in this dir!\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/vscode/.local/lib/python3.10/site-packages/pymatgen/io/cif.py:1169: UserWarning: Issues encountered while parsing CIF: Some fractional coordinates rounded to ideal values to avoid issues with finite precision.\n", " warnings.warn(\"Issues encountered while parsing CIF: \" + \"\\n\".join(self.warnings))\n" ] } ], "source": [ "my_interface = core('cif_files/WS2_single_layer.cif',\\\n", " 'cif_files/WS2_single_layer.cif')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Searching two_dimensional CSL" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "#a known target disorientation giving CSL\n", "R = rot(a=[0,0,1],theta = 18/180 * pi)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Congrates, we found an appx CSL!\n", "\n", "U1 = \n", "[[-5 6]\n", " [ 1 5]\n", " [ 0 0]]; sigma_1 = 31\n", "\n", "U2 = \n", "[[-6 5]\n", " [-1 6]\n", " [ 0 0]]; sigma_2 = 31\n", "\n", "D = \n", "[[ 9.9999969e-01 7.5841000e-04 -0.0000000e+00]\n", " [-7.5825000e-04 9.9999974e-01 0.0000000e+00]\n", " [ 0.0000000e+00 -0.0000000e+00 1.0000000e+00]]\n", "\n", "axis = [ 5.39873138e-16 9.35087575e-16 -8.81679743e+00] ; theta = 0.06\n", "\n" ] } ], "source": [ "my_interface.parse_limit(du = 1e-3, S = 1e-3, sgm1=100, sgm2=100, dd = 1e-3)\n", "#Do searching!\n", "my_interface.search_one_position_2D(hkl_1=[0,0,1], hkl_2 = [0,0,1], theta_range = 2, dtheta= 0.01, pre_dt=True,pre_R=R, exact=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get bicrystal" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cell 1:\n", "[[ 0 -5 -6]\n", " [ 0 1 -5]\n", " [ 1 0 0]]\n", "cell 2:\n", "[[ 0 -6 -5]\n", " [ 0 -1 -6]\n", " [ 1 0 0]]\n" ] } ], "source": [ "hkl = get_primitive_hkl([0, 0, 1], my_interface.conv_lattice_1, my_interface.lattice_1)\n", "my_interface.compute_bicrystal_two_D(hkl_1=[0,0,1], hkl_2 = [0,0,1],normal_ortho = False, lim = 50, tol_ortho = 1e-2, tol_integer=1e-3)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "#layer_displacement = 3.4\n", "#my_interface.get_bicrystal(xyz_1 = [1,1,1], xyz_2 = [1,1,1], \\\n", " #dp1 = 9.99905800e+00 - layer_displacement, filetype= 'VASP')\n", "my_interface.get_bicrystal(xyz_1 = [1,1,1], xyz_2 = [1,1,1], filetype= 'VASP', dp1 = 0)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Sample CNID " ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "gridsize = 0.3\n", "n1 = int(ceil(norm(my_interface.CNID[:,0])/gridsize))\n", "n2 = int(ceil(norm(my_interface.CNID[:,1])/gridsize))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CNID\n", "[[-0.16129032 0.19354839]\n", " [ 0.03225806 0.16129032]\n", " [-0. -0. ]]\n", "making 4 files...\n", "completed\n" ] } ], "source": [ "import shutil\n", "try:\n", " shutil.rmtree('CNID_inputs')\n", "except:\n", " print('No existing files')\n", "my_interface.sample_CNID([n1,n2], dp1 = 0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Please check the POSCAR file" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" }, "vscode": { "interpreter": { "hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1" } } }, "nbformat": 4, "nbformat_minor": 4 }